package bootstrap

import (
	"common/model/admin"
	"fmt"
	"github.com/glebarez/sqlite"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

var GDB *gorm.DB
var path = "./test.db"

func Bootstrapper() {
	initGDb()
}

func initGDb() {
	db, err := gorm.Open(sqlite.Open(path), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})
	if err != nil {
		panic("failed to connect database")
	}
	GDB = db
}

func createTable() {
	err := GDB.AutoMigrate(&admin.AdminUser{})
	if err != nil {
		fmt.Errorf("用户表%s创建失败", "admin_user")
	}
}
